#!/usr/bin/python# coding=utf8
#
# Copyright (C) 2011 XNData contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


__author__ = "zhangchitc@gmail.com"



import datetime

class Profile:
    uid             = ""
    name            = ""
    sex             = ""        # either 'M' or 'F'
    birth           = None      # should be a date object
    hometown_p      = ""        # province of user's hometown
    hometown_c      = ""        # city of user's hometown

    college         = ""
    college_grad    = -1        # graduation year
    college_dept    = ""        # department of user's major
    highschool      = ""        
    juniorschool    = ""
    primaryschool   = ""

    qq              = ""
    email           = ""
    phone           = ""

    def set_uid (self, uid):
        self.uid = uid

    def set_name (self, name):
        self.name = name

    def set_sex (self, sex):
        self.sex = sex

    def set_birth (self, year, month, day):
        self.birth = datetime.date (year, month, day)

    def set_hometown_p (self, hometown_p):
        self.hometown_p = hometown_p

    def set_hometown_c (self, hometown_c):
        self.hometown_c = hometown_c

    def set_college (self, college):
        self.college = college

    def set_college_grad (self, college_grad):
        self.college_grad = college_grad

    def set_college_dept (self, college_dept):
        self.college_dept = college_dept

    def set_highschool (self, highschool):
        self.highschool = highschool

    def set_juniorschool (self, juniorschool):
        self.juniorschool = juniorschool

    def set_primaryschool (self, primaryschool):
        self.primaryschool = primaryschool

    def set_qq (self, qq):
        self.qq = qq

    def set_email (self, email):
        self.email = email

    def set_phone (self, phone):
        self.phone = phone

    def __repr__ (self):
        ret = ""
        if self.uid: ret += "uid = %s\n" % self.uid
        if self.name: ret += "name = %s\n" % self.name
        if self.sex: ret += "sex = %s\n" % self.sex
        if self.birth: ret += "birth = %s\n" % self.birth
        if self.hometown_p: ret += "hometown_p = %s\n" % self.hometown_p
        if self.hometown_c: ret += "hometown_c = %s\n" % self.hometown_c
        if self.college: ret += "college = %s\n" % self.college
        if self.college_grad: ret += "college_grad = %s\n" % self.college_grad
        if self.college_dept: ret += "college_dept = %s\n" % self.college_dept
        if self.highschool: ret += "highschool = %s\n" % self.highschool
        if self.juniorschool: ret += "juniorschool = %s\n" % self.juniorschool
        if self.primaryschool: ret += "primaryschool = %s\n" % self.primaryschool
        if self.qq: ret += "qq = %s\n" % self.qq
        if self.email: ret += "email = %s\n" % self.email
        if self.phone: ret += "phone = %s\n" % self.phone
        return ret
 
    def __str__ (self):
        return self.__repr__ ()


class SimpleProfile:
    
    user_id = ""
    name = ""
    tinyphoto_url = ""
    school = ""
    city = ""

    def __init__ (self, user_id = None, name = None, tinyphoto_url = None,
                    school = None, city = None):
        self.user_id = user_id
        self.name = name
        self.tinyphoto_url = tinyphoto_url
        self.school = school
        self.city = city

    def __repr__ (self):
        ret = ""
        ret += "user_id = %s\n" % self.user_id
        ret += "name = %s\n" % self.name
        ret += "tinyphoto_url = %s\n" % self.tinyphoto_url
        if self.school != "":
            ret += "school = %s\n" % self.school
        if self.city != "":
            ret += "city = %s\n" % self.city
        return ret

    def __str__ (self):
        return self.__repr__ ()


class FriendList:
    
    user_id = ""
    cur_page = -1
    friend_list = []

    def __init__ (self, user_id = None, cur_page = None):
        self.user_id = user_id
        self.cur_page = cur_page
        self.friend_list = []

    def __repr__ (self):
        ret = ""
        ret += "user_id = %s\n" % self.user_id
        ret += "cur_page = %s\n" % self.cur_page
        for i, profile in zip (xrange (len (self.friend_list)), self.friend_list):
            ret += " " * 12 + "*****   [%dth friend]  *****\n" % i
            ret += str (profile)
        return ret

    def __str__ (self):
        return self.__repr__ ()

    def __len__ (self):
        return len (self.friend_list)

    def __getitem__ (self, index):
        return self.friend_list[index]

    def addFriend (self, friend_profile):
        self.friend_list.append (friend_profile)


if __name__ == "__main__":

    # test if object print well
    profile = Profile()
    profile.set_uid ("242124580")
    profile.set_name ("张弛")
    profile.set_sex ("M")
    profile.set_birth (1989, 5, 8)
    profile.set_hometown_p ("湖南")
    profile.set_hometown_c ("长沙")
    profile.set_college ("北京大学")
    profile.set_college_grad ("2008")
    profile.set_college_dept ("信息科学技术学院")
    profile.set_highschool ("雅礼中学")
    profile.set_juniorschool ("雅礼中学")
    profile.set_primaryschool ("仰天湖小学")
    profile.set_qq ("286743108")
    profile.set_email ("zhangchitc@gmail.com")
    profile.set_phone ("secret")
    print profile 

